package com.rayboot.footpoint.utils;

import android.content.Context;

import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.rayboot.footpoint.R;

public class MyLocationUtil {
	private static MyLocationUtil mInstance;
	private Context context;
	private LocationClient mLocationClient;
	LocationClientOption option;

	public MyLocationUtil(Context context) {
		this.context = context;
		mLocationClient = new LocationClient(context);
		option = new LocationClientOption();
		setDefaultLocationParam();
		start();
	}

	public static void init(Context context) {

		if (mInstance == null) {
			mInstance = new MyLocationUtil(context);
		}
	}

	public static void unInit() {
		// TODO Auto-generated method stub
		if (mInstance != null) {
			mInstance.stop();
		}
	}

	private void setDefaultLocationParam() {
		if (mLocationClient == null)
			return;
		option.setOpenGps(true);
		option.setAddrType("detail");
		option.setCoorType("gcj02");
		option.setScanSpan(5000);
		option.setPriority(LocationClientOption.NetWorkFirst);
		option.setProdName(context.getString(R.string.app_name));
		mLocationClient.setLocOption(option);
	}

	private void start() {
		mLocationClient.start();
	}

	private void stop() {
		mLocationClient.stop();
	}

	public static LocationClient getLocationClient() {
		return null == mInstance ? null : mInstance.mLocationClient;
	}
}
